package cn.gson.fengboot.controller;

import cn.gson.fengboot.model.pojos.*;
import cn.gson.fengboot.model.service.TfyClueService;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@Controller
public class TfyClueController {
    @Autowired
    TfyClueService tfyClueService;

    @RequestMapping("clue-list")
    @ResponseBody
    public Map<String,Object> clueList(Integer page,Integer size,String search){
        System.out.println(page);
        System.out.println(size);
        //线索分页查询
        Page<Object> obj = PageHelper.startPage(page, size);
        List<TfyclueForm> allClue = tfyClueService.findAllClue(search);
        //封装数据
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",allClue);
        return map;
    }

    @RequestMapping("cluezt-list")
    @ResponseBody
    public Map<String,Object> clueztList(Integer page,Integer size,String search){
        System.out.println(page);
        System.out.println(size);
        //失效线索分页查询
        Page<Object> obj = PageHelper.startPage(page, size);
        List<TfyclueForm> allClue = tfyClueService.findAllCluezt(search);
        //封装数据
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",allClue);
        return map;
    }

    @RequestMapping("clueclient-list")
    @ResponseBody
    public Map<String,Object> ClueClientList(Integer page,Integer size,String search){
        System.out.println(page);
        System.out.println(size);
        //分配给我的线索查询
        Page<Object> obj = PageHelper.startPage(page, size);
        List<TfyclueForm> allclueclient = tfyClueService.findClueClient(search);
        //封装数据
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",allclueclient);
        return map;
    }

    @PostMapping("/addclue-list")
    @ResponseBody
    public void addclue(@RequestBody TfyclueForm xs){
        //新增线索方法
        tfyClueService.addclue(xs);
    }

    @PostMapping("/deleteclue-list")
    @ResponseBody
    public void deleteClue(String cluedx){
        //逻辑删除线索
        tfyClueService.deleteClue(cluedx);
    }

    @PostMapping("/hfclue-list")
    @ResponseBody
    public void hfClue(String cluedx){
        //恢复线索修改
        tfyClueService.hfClue(cluedx);
    }

    @PostMapping("/scclue-list")
    @ResponseBody
    public void scClue(String cluedx){
        //物理删除线索
        tfyClueService.scClue(cluedx);
    }

    @RequestMapping("/selectxsid-list")
    @ResponseBody
    public TfyclueForm findXskh(Integer clueId){
        //根据线索id查询对应线索和客户方法
        return tfyClueService.findXskh(clueId);
    }

    @PostMapping("/gjclue-list")
    @ResponseBody
    public void gjztClue(String cluedx){
        //修改线索跟进状态
        tfyClueService.gjztClue(cluedx);
    }

    @PostMapping("/pinkclient-list")
    @ResponseBody
    public void pinkclient(String xs){
        //线索 ->新增为客户和联系人
        JSONObject obj=(JSONObject)JSONObject.parse(xs);
        TfyclueForm xs1=obj.getObject("xs",TfyclueForm.class);
        tfyClueService.pinkclient(xs1);
        System.out.println("12"+xs);
    }

}
